//
//  MainViewController.swift
//  Sina
//
//  Created by 王杰 on 15/11/11.
//  Copyright © 2015年 王杰. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @objc func composeDidClick() {
    
//    print(__FUNCTION__)

        let compose = ComposeViewController()
        let nav = UINavigationController(rootViewController: compose)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    override func viewDidLoad() {
        let mainTabBar = MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
        
        addChildViewControllers()
        print(tabBar.classForCoder)
    }
    
    
    private func addChildViewControllers() {
        
      addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    
    private func addChildViewController(vc: UIViewController,imageName:String,title:String) {
    
        let nav = BaseNavViewController(rootViewController: vc)

        vc .title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
        
    }
}
